import torch
import numpy as np
from torch.utils.data import Dataset    # Dataset 是一个抽象类，要继承它
from torch.utils.data import DataLoader

class DiabetesDataset(Dataset):
    def __init__(self,path):
        xy = np.loadtxt(path,delimiter=',',dtype=np.float32)
        self.len = xy.shape[0]
        self.x_data = torch.from_numpy(xy[:,:-1])
        self.y_data = torch.from_numpy(xy[:,[-1]])

    def __getitem__(self, index):
        return self.x_data[index],self.y_data[index]

    def __len__(self):
        return self.len

